<?php

if (!defined('IN_XLP')) {
    exit('Access Denied!');
}


/**
 * Description of sms
 * 三要素认证接口
 * @author xlp
 */
class auth {

    public static $errInfo = null;
    public static $config = array();
    public static $privateKey = '6f1b99166c034899b676658b1ba2a022';

    static public function init() {
        self::$config = array(
            'account'  => 'renrenyong-api'
        );
    }

    static public function goAuth($objData) {
        self::init();
        self::$config['name']    = $objData['username'];
        self::$config['cid']     = $objData['card_num'];
        self::$config['card']    = $objData['bank_account'];
        self::$config['reqTid']  = getRandInt(8);
        $tempArray = self::$config;
        ksort(self::$config);
        $signStr = '';
        foreach (self::$config as $k => $v) {
            $signStr .= $k.$v;
        }
        $signStr = $signStr.self::$privateKey;
        $sign = strtoupper(md5($signStr));
        $url = "https://api.ccxcredit.com/data-service/auth/cnc/t2?";
        $urlParam = '';
        foreach ($tempArray as $key => $val) {
            $urlParam .= $key.'='.urlencode($val).'&'; 
        }
        $urlParam .= 'sign='.$sign;
        $url = $url.$urlParam;
        $result = getHttp($url);
        $res = json_decode($result, true);
        if($res['resCode'] == 2030){
            return true;
        }else{
            self::$errInfo = $res['resMsg'];
            return false;
        }
    }


    static public function gerError() {
        return self::$errInfo;
    }

}
